<?php
class user{
	
	//variables de la classe user
	private $u_login;
	private $u_film;
	private $u_music;
	private $u_admin;
	
	//constructeur
	function __construct() {
		$this->u_login ="anonyme";
		$this->u_film = 0;
		$this->u_music = 0;
		$this->u_admin = 0;
	}
	//accesseur
	function __get($value){
		if('login' == $value) {
			return $this->u_login;
		}
		elseif('film' == $value){
			return $this->u_film;
		}elseif('music' == $value){
			return $this->u_music;
		}elseif('admin' == $value){
			return $this->u_admin;
		}else{
			return "error invalid argument";
		}
	}
	
	function check_password($login,$password){
		mysql_connect(DATABASE_ADDRESS, DATABASE_USER, DATABASE_PASS);
		mysql_select_db(DATABASE_NAME);
		$sql_query = mysql_query("Select film,password,music,admin from user WHERE login = '".$login."' ORDER BY `id` ASC");
		while ($query = mysql_fetch_array($sql_query)){
			if (md5($password)==$query['password']){
				$this->u_login = $login;
				$this->u_film = $query['film'];
				$this->u_music = $query['music'];
				$this->u_admin= $query['admin'];
				mysql_close();
				return true;		
			}
		}
	mysql_close();	
	return false;
	}
	

}
?>